package dp;

import java.util.Arrays;

/**
 * 396. 旋转函数
 */
public class P396 {
    public int maxRotateFunction(int[] nums) {
        int len = nums.length;
        int sum = Arrays.stream(nums).sum();
        int total = 0;
        for (int i = 0; i < len; i++) {
            total += i * nums[i];
        }
        int max = total;
        for (int i = 1; i < len; i++) {
            int tmp = total + sum - len * nums[len - i];
            total = tmp;
            if (total > max) {
                max = total;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{4, 3, 2, 6};
        int max = new P396().maxRotateFunction(nums);
        System.out.println(max);
    }
}
